package user;

import java.util.Map;
import java.util.TreeMap;

/**
 * 押注区数据(某押注区)
 */
public class BetData {
    int mIdx; // 区索引
    int mSumScore; // 总分=倍率*积分 结算时计算
    int mRatio; // 倍率

    // 押注分-->数量
    Map<Integer, Integer> mScores = new TreeMap<>();

    public BetData(int idx, int ratio) {
        mIdx = idx;
        mRatio = ratio;
    }

    /**
     * 添加押注积分
     * 
     * @param score
     */
    public void add(int score) {
        Integer ig = mScores.computeIfAbsent(score, k -> (0));
        ig++;
        mScores.put(score, ig);// 覆盖
    }

    /**
     * 计算押注总额 含倍率
     * 
     * @return 建议返回long
     */
    public void calcScore() {
        mSumScore = 0;
        for (Integer k : mScores.keySet()) {
            mSumScore += k * mScores.get(k); // 积分*数量
        }
        mSumScore *= mRatio; // 倍率
    }

    /**
     * 获取区积分
     * 
     * @return
     */
    public int getScore() {
        return mSumScore;
    }

    /**
     * 获取倍率
     * 
     * @return
     */
    public int getRatio() {
        return mRatio;
    }

    public int getIdx() {
        return mIdx;
    }

    /**
     * 数据描述
     * 
     * @return
     */
    public String info() {
        String str = new String();
        str += "idx:" + Integer.toString(mIdx) + ",";
        for (Integer k : mScores.keySet()) {
            String o = "{score:" + Integer.toString(k) + ", ";
            o += "num:" + Integer.toString(mScores.get(k)) + "}  ";
            str += o; // 这个在forEach中有问题
        }
        /*
         * mScores.forEach((k, v) -> {
         * 
         * });
         */
        str += ", ratio:" + Integer.toString(mRatio);
        str += ", sumScore:" + Integer.toString(mSumScore);
        return str;
    }
}
